package com.liao.controller;

import com.liao.bean.ServerCount;
import com.liao.bean.result.Code;
import com.liao.bean.result.Msg;
import com.liao.bean.result.PageResult;
import com.liao.bean.result.Result;
import com.liao.service.ServerCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/serverCount")
public class ServerCountController {

    /**
     * 分页模糊查询客户业绩表
     */
    @Autowired
    private ServerCountService serverCountService;

    @ResponseBody
    @RequestMapping("/queryServerCountListByPage")
    public PageResult<ServerCount> queryServerCountListByPage(Integer currentPage,Integer pageSize,String scid) throws Exception {

      PageResult<ServerCount> pageResult=  serverCountService.queryServerCountListByPage(currentPage,pageSize,scid);

      return pageResult;
    }

    /**
     * 删除
     * @param scid
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteServerCountById")
    public Result deleteServerCountById(String scid) throws Exception {

        serverCountService.deleteServerCountById(scid);

        return new Result(true, Code.SERVERDEL_SUCCESS, Msg.SERVERDEL_SUCCESS,null);
    }

    /**
     * 批量删除
     * @param scids
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteServerCountByIdS")
    public Result deleteServerCountByIdS(@RequestParam("scids[]")List<String> scids) throws Exception {

        for (String scid : scids) {
            serverCountService.deleteServerCountById(scid);
        }

        return new Result(true, Code.SERVER_DEL, Msg.SERVER_DEL,null);
    }

    /**
     * 添加
     * @param scid
     * @param orderId
     * @param orderMoney
     * @param serverMoney
     * @return
     */
    @ResponseBody
    @RequestMapping("/addServerCount")
    public Result addServerCount(String scid,String orderId,String orderMoney,String serverMoney) throws Exception {

        serverCountService.addServerCount(scid,orderId,orderMoney,serverMoney);

        return new Result(true, Code.SERVER_ADD, Msg.SERVER_ADD,null);
    }

    /**
     * 根据scid修改用户
     * @param scid
     * @param orderId
     * @param orderMoney
     * @param serverMoney
     * @return
     */
    @ResponseBody
    @RequestMapping("/updateServerCount")
    public Result updateServerCount(String scid,String orderId,String orderMoney,String serverMoney) throws Exception {
        serverCountService.updateServerCount(scid,orderId,orderMoney,serverMoney);

        return new Result(true, Code.SERVER_UPDATE, Msg.SERVER_UPDATE,null);
    }
}
